/*
 *  txdnet.cn tonydon
 * 
 */
package cn.txdnet.txcms.service;

import cn.txdnet.key.GenId;
import cn.txdnet.txcms.dao.HotShopDAO;
import cn.txdnet.txcms.domain.HotShop;
import cn.txdnet.txcms.dto.PageDTO;
import cn.txdnet.txcms.query.HotShopQuery;
import cn.txdnet.txcms.query.ViewHotShopQuery;
import cn.txdnet.txweb.basedao.FacadeProxy;
import cn.txdnet.txweb.utils.StringUtil;
import java.util.HashMap;
import java.util.Map;
import txdnet.util.StaticMark;

/**
 *
 * @author txdnet
 */
public class HotShopService {

    /**
     * 保存SHOP信息
     *
     * @param shop
     * @return
     */
    public static boolean make(HotShop shop) {
        HotShopDAO dao = FacadeProxy.getManualCommitProxy(HotShopDAO.class);
        shop.setShopid(GenId.makeSid());
        return (dao.insertHotShop(shop) > 0 ? true : false);
    }

    /**
     * 更新商铺信息
     *
     * @param shop
     * @return
     */
    public static boolean update(HotShop shop) {
        HotShopDAO dao = FacadeProxy.getManualCommitProxy(HotShopDAO.class);
        return (dao.updateHotShop(shop) > 0 ? true : false);
    }

    /**
     * 更新发布状态
     *
     * @param ids
     * @param pubstate
     * @return
     */
    public static int updatePubstate(String ids, byte pubstate) {
        Map<String, Object> m = new HashMap<String, Object>(2);
        m.put("ida", StringUtil.parseStrToLongArray(ids, StaticMark.STR_LINE));
        m.put("pubstate", pubstate);
        HotShopDAO dao = FacadeProxy.getManualCommitProxy(HotShopDAO.class);
        return dao.updatePubstate(m);
    }

    /**
     * 更新评论状态
     *
     * @param ids
     * @param iscmt
     * @return
     */
    public static int updateCmtstate(String ids, byte iscmt) {
        Map<String, Object> m = new HashMap<String, Object>(2);
        m.put("ida", StringUtil.parseStrToLongArray(ids, StaticMark.STR_LINE));
        m.put("iscmt", iscmt);
        HotShopDAO dao = FacadeProxy.getManualCommitProxy(HotShopDAO.class);
        return dao.updateCmtstate(m);
    }

    /**
     * 更新发布时间
     *
     * @param ids
     * @param pubtime
     * @return
     */
    public static int updatePubTime(String ids, long pubtime) {
        Map<String, Object> m = new HashMap<String, Object>(2);
        m.put("ida", StringUtil.parseStrToLongArray(ids, StaticMark.STR_LINE));
        m.put("pubtime", pubtime);
        HotShopDAO dao = FacadeProxy.getManualCommitProxy(HotShopDAO.class);
        return dao.updatePubTime(m);
    }

    /**
     * 更新时间
     *
     * @param ids
     * @param updatetime
     * @return
     */
    public static int updateTime(String ids, long updatetime) {
        Map<String, Object> m = new HashMap<String, Object>(2);
        m.put("ida", StringUtil.parseStrToLongArray(ids, StaticMark.STR_LINE));
        m.put("updatetime", updatetime);
        HotShopDAO dao = FacadeProxy.getManualCommitProxy(HotShopDAO.class);
        return dao.updateTime(m);
    }

    /**
     * 更新商铺类目
     *
     * @param ids
     * @param cid
     * @param ctp
     * @return
     */
    public static int updateCatalogBatch(String ids, int cid, String ctp) {
        Map<String, Object> m = new HashMap<String, Object>(4);
        m.put("ida", StringUtil.parseStrToLongArray(ids, StaticMark.STR_LINE));
        m.put("cid", cid);
        m.put("ctp", ctp);
        HotShopDAO dao = FacadeProxy.getManualCommitProxy(HotShopDAO.class);
        return dao.updateCatalog(m);
    }

    /**
     * 删除商铺信息
     *
     * @param ids
     * @return
     */
    public static int deleteBatch(String ids) {
        HotShopDAO dao = FacadeProxy.getManualCommitProxy(HotShopDAO.class);
        return dao.deleteHotShop(StringUtil.parseStrToLongArray(ids, StaticMark.STR_LINE));
    }

    /**
     * 更新查看次数
     *
     * @param shopid
     * @return
     */
    public static int increaseHitNum(long shopid) {
        return FacadeProxy.getManualCommitProxy(HotShopDAO.class).increaseHitNum(shopid);
    }

    /**
     * 更具查询条件得到记录
     *
     * @param query
     * @return
     */
    public static PageDTO queryByFactor(HotShopQuery query) {
        HotShopDAO dao = FacadeProxy.getAutoCommitProxy(HotShopDAO.class);
        return dao.queryByFactor(query);
    }

    /**
     * 查询商铺信息用于编辑
     *
     * @param shopid
     * @return
     */
    public static HotShop queryShopForEdit(long shopid) {
        HotShopDAO dao = FacadeProxy.getAutoCommitProxy(HotShopDAO.class);
        return dao.queryShopForEdit(shopid);
    }

    /**
     * 查询商铺信息
     *
     * @param query
     * @return
     */
    public static HotShop queryShopForView(long shopid) {
        ViewHotShopQuery query = new ViewHotShopQuery();
        query.setShopid(shopid);
        query.filter();
        HotShopDAO dao = FacadeProxy.getAutoCommitProxy(HotShopDAO.class);
        return dao.queryShopForView(query);
    }
}
